﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Skyhook.Core;
using Skyhook.Core.Graphics;

namespace Skyhook.Resources
{
    public class Image : Resource
    {
        const string FileExtension = ".png";

        Texture2D XNATexture = null;

        string Name = "NULL_RESOURCE";

        public Image()
        {
        }

        public override bool IsEmpty
        {
            get
            {
                return (XNATexture == null);
            }
        }

        public override string UID
        {
            get
            {
                return Name;
            }
        }

        internal override void LoadFromFile(string assetname)
        {
            Stream stream = StreamFactory.Create(assetname + FileExtension);
            XNATexture = GraphicsFactory.CreateTexture2DFromStream(stream);
            stream.Close();

            Name = assetname;
        }

        public static implicit operator Texture2D(Image texture)
        {
            return texture.XNATexture;
        }
    }
}
